function Add-SQLPSSnapin
{
	#
	# Add the SQL Server Provider.
	#

	$ErrorActionPreference = "Stop"

	$sqlpsreg="HKLM:\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.SqlServer.Management.PowerShell.sqlps"

	if (Get-ChildItem $sqlpsreg -ErrorAction "SilentlyContinue")
	{
		throw "SQL Server Provider for Windows PowerShell is not installed."
	}
	else
	{
		$item = Get-ItemProperty $sqlpsreg
		$sqlpsPath = [System.IO.Path]::GetDirectoryName($item.Path)
	}


	#
	# Set mandatory variables for the SQL Server provider
	#
	Set-Variable -scope Global -name SqlServerMaximumChildItems -Value 0
	Set-Variable -scope Global -name SqlServerConnectionTimeout -Value 30
	Set-Variable -scope Global -name SqlServerIncludeSystemObjects -Value $false
	Set-Variable -scope Global -name SqlServerMaximumTabCompletion -Value 1000

	#
	# Load the snapins, type data, format data
	#
	Push-Location
	cd $sqlpsPath
	if( ! ( Get-PSSnapin | where { $_.Name -ieq "SqlServerCmdletSnapin100" } ) )
	{
		Add-PSSnapin SqlServerCmdletSnapin100
	}
	
	if( ! ( Get-PSSnapin | where { $_.Name -ieq "SqlServerProviderSnapin100" } ) )
	{
		Add-PSSnapin SqlServerProviderSnapin100

		Update-TypeData -PrependPath SQLProvider.Types.ps1xml 
		Update-FormatData -prependpath SQLProvider.Format.ps1xml 
	}
	Pop-Location
}